package com.example.composewanandroid

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
import com.example.composewanandroid.navigation.LocalNavController
import com.example.composewanandroid.ui.WanApp
import com.example.composewanandroid.ui.theme.ComposeWanAndroidTheme
import dagger.hilt.android.AndroidEntryPoint

// 标记为Hilt的Android入口点（自动处理依赖注入）
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            ComposeWanAndroidTheme {
                // 创建导航控制器
                val navController = rememberNavController()

                // 提供导航控制器给整个应用
                CompositionLocalProvider(LocalNavController provides navController) {
                    // 主应用组件
                    WanApp(navController)
                }
            }
        }
    }

    override fun onResume() {
        super.onResume()
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    ComposeWanAndroidTheme {
        Greeting("Android")
    }
}